#include "StdAfx.h"
#include "LeafOperator.h"


LeafOperator::LeafOperator(void)
{
}


LeafOperator::~LeafOperator(void)
{
}
void LeafOperator::setStreamInput(boost::shared_ptr<IStreamInput> streamInput)
{
	this->streamInput = streamInput;
	this->streamInput->initial();
}

void LeafOperator::execution(int executionTimes)
{
#ifdef DEBUG
	std::cout<<"===================operator begin================="<<std::endl;
	std::cout<<"operatorid : "<<this->getId()<<std::endl;
#endif

	boost::shared_ptr<QueueEntity>outputQueue = this->getOutputQueueList().front();
	for(int i = 0 ; i < executionTimes ;i++)
	{
		if(outputQueue->isFull())
		{
			return;
		}
		if(streamInput->isEmpty())
		{
			return;
		}
		Element element;
		bool bl = streamInput->getAndCheckNextElement(element);
		if(bl == true)
		{
			outputQueue->enqueue(element);
		}
		else
		{
			std::cout<<"the input element doesn't satisfied the schema"<<std::endl;
		}
		
	}
#ifdef DEBUG
	std::cout<<"===================operator over================="<<std::endl;
#endif
}
